#include "texture.h"
#include <iostream>
#include <fstream>
#include <SDL/SDL.h>

Texture::Texture () {
	image = NULL;
}

void Texture::Load (const std::string & file) throw(Error) {
	image = SDL_LoadBMP(file.c_str());
	if (!image) {
		throw Error("Failed to load texture");
	}
}

Texture::~Texture () {
}

SDL_Surface * Texture::GetTexture () {
	return image;
}

void Texture::Draw (SDL_Surface * screen, int x, int y, int state) {
	SDL_Rect dst, src;
	src.y = 0;
	src.x = state * TEXTURE_SZ;
	src.w = src.h = TEXTURE_SZ;

	dst.x = x * TEXTURE_SZ;
	dst.y = y * TEXTURE_SZ;
	SDL_BlitSurface(image, &src, screen, &dst);
}

void Texture::Draw (SDL_Surface * screen, SDL_Rect & dst, int state) {
	SDL_Rect src;
	src.y = 0;
	src.x = state * TEXTURE_SZ;
	src.w = src.h = TEXTURE_SZ;

	SDL_BlitSurface(image, &src, screen, &dst);
}

void Texture::Draw (SDL_Surface * screen, SDL_Rect & dst, SDL_Rect & src) {
	SDL_BlitSurface(image, &src, screen, &dst);
}
